package com.example.analysis.service.impl;

import com.example.analysis.entity.College;
import com.example.analysis.mapper.CollegeDao;
import com.example.analysis.service.CollegeService;
import com.example.analysis.utils.Response;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class CollegeServiceImpl implements CollegeService {
    @Resource
    private CollegeDao CollegeDao;


    @Override
    public Response<College> insert(College aCollege) {
        try {
            CollegeDao.insert(aCollege);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<College> getById(String CollegeId) {
        College aCollege = CollegeDao.selectByPrimaryKey(CollegeId);
        if (aCollege != null) {
            return new Response<>(true, "Success", aCollege);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<College> getByName(String CollegeName) {
        College aCollege = CollegeDao.selectByName(CollegeName);
        if (aCollege != null) {
            return new Response<>(true, "Success", aCollege);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
